﻿const http = require('http');

module.exports = function getResponseText(path) {
    return new Promise(function (resolve, reject) {
        http.get(path, res => {
            const { statusCode } = res;
            if (statusCode !== 200) {
                var errMsg = `request failed (err: ${statusCode}).`;
                console.log(errMsg);
                reject(new Error(errMsg));
                return
            }

            res.setEncoding('utf8');
            let output = '';
            res.on('data', chunk => output += chunk);
            res.on('end', async () => resolve(output));
        })
    })
}